<?php

/**
 * main actions.
 *
 * @package    tvpv
 * @subpackage main
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 9301 2008-05-27 01:08:46Z dwhittle $
 */
class mainActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex($request)
  {
    //$this->forward('default', 'module');
  }
  
  public function executeArticulos($request){
  	/*if( $request->getParameter('page'))
  	  $this->articulos_List = ArticuloPeer::getArtByCategoria($request->getParameter('page'),$request->getParameter('cat'));
    else*/
    $this->articulosList = ArticuloPeer::getArtByCategoria($request->getParameter('cat'), $request->getParameter('orden'),  $request->getParameter('page'));
    //$this->redirect('main/articulos');
  }
  
  public function executeBuscar($request){
  	$this->articulosList = ArticuloPeer::getArtBySearch($this->getRequestParameter('search'), $request->getParameter('orden'), $request->getParameter('page'));
  }
  
  public function executeShow($request){
  	$this->forward404Unless($this->getRequestParameter('id'));
  	$this->articulo = ArticuloPeer::retrieveByPK($this->getRequestParameter('id'));
  	$this->relacionados = ArticuloPeer::getRelacionados($this->getRequestParameter('id'));
  }
  
  public function executeSuscribir($request){
  	$this->forward404Unless($request->isMethod('post'));
  	//$email = $request->getParameter('email');
  	$email = $this->getRequestParameter('email');
  	$c = new Criteria();
    $c->add(SuscripcionPeer::EMAIL, $email);
    $suscripcion = SuscripcionPeer::doSelectOne($c);
    
  	if ($this->getRequestParameter('suscribir') == 'Off')
  	{
  		$suscripcion->delete();
  	}
  	if ($this->getRequestParameter('suscribir') == 'On')
  	{
  		if($suscripcion == NULL ){
  	    $this->form = new SuscripcionForm();
	  	  $this->form->bind(array('email'=>$email));	  	  
	  	  if($this->form->isValid()){
	  	  	$this->form->save();	
	  	  }
	  	  else
	  	  {
	  	  	$this->error = "Email Invalido";
	  	  }
	  	  
  		}
  	}
  	$this->setTemplate('index');
  }
}
